<article id="wikiArticle">
<div></div>
<div class="warning"><strong>?警告:</strong>传统迭代协议是一个SpiderMonkey特性, 并且在将来可能会被移除。请使用<a href="https://developer.mozilla.orgReference/Statements/for...of">for..of</a> 循环与<a href="https://developer.mozilla.orgReference/Iteration_protocols">迭代协议</a>。</div>
<h2 id="废弃的Firefox专属迭代协议">废弃的Firefox专属迭代协议</h2>
<p>Firefox在version 26版本生效的与<a href="https://developer.mozilla.orgReference/Iteration_protocols">ES2015迭代协议</a>相似的另一种迭代协议。以下统称为旧迭代协议。</p>
<p>?旧迭代器对象在使用next()方法时，会在循环到最后时抛出<a class="new" href="Reference/Global_Objects/StopIteration" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>StopIteration</code></a>。</p>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">属性</th>
<th scope="col">??描述</th>
</tr>
<tr>
<td><code>next</code></td>
<td>一个会返回值的无参数函数</td>
</tr>
</tbody>
</table>
<h3 id="旧迭代器与ES6迭代器的区别">?旧迭代器与ES6迭代器的区别</h3>
<ul>
<li>?旧迭代器在调用next的时候立即返回相应的值而不会返回一个代理对象。</li>
<li>循环遍历中通过抛出<a class="new" href="Reference/Global_Objects/StopIteration" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>StopIteration</code></a>对象结束循环。</li>
</ul>
<h3 id="旧迭代器协议示例">旧迭代器协议示例</h3>
<pre><code  class="language-javascript">function makeIterator(array){
    var nextIndex = 0;

    return {
       next: function(){
           if(nextIndex &lt; array.length){
               return array[nextIndex++];
           else
               throw new StopIteration();
       }
    }
}

var it = makeIterator(['yo', 'ya']);

console.log(it.next()); // 'yo'
console.log(it.next()); // 'ya'
try{
    console.log(it.next());
}
catch(e){
    if(e instanceof StopIteration){
         // iteration over
    }
}
</code></pre>
<h2 id="参见">?参见</h2>
<ul>
<li><a href="https://developer.mozilla.orgGuide/Iterators_and_Generators">迭代器和生成器</a></li>
<li>?更多<a href="https://developer.mozilla.orgReference/Deprecated_and_obsolete_features">废弃与过时的JavaScript属性</a></li>
</ul>
</article>